package April._22.work2;

import java.io.FileWriter;
import java.io.IOException;

public class GuessPassword implements Runnable{
    private final String password;
    public FileWriter out;
    @Override
    public void run() {
        for (int i = 0; i < 10; i++) {
            for (int j = 0; j < 10; j++) {
                for (int k = 0; k < 10; k++) {
                    String guess=""+i+j+k;
                    if(guess.equals(password)){
                        try {
                            this.out.write(guess);
                            out.flush();
                            System.out.println("guess = " + guess);
                            System.out.println("guess success");
                        } catch (IOException e) {
                            throw new RuntimeException(e);
                        }
                        return;
                    }else{
                        try {
                            this.out.write(guess+"  ");
                            out.flush();
                        } catch (IOException e) {
                            throw new RuntimeException(e);
                        }
                    }
                }
            }
        }
    }

    public GuessPassword(String password, FileWriter out) {
        this.password = password;
        this.out = out;
    }
}
